import java.io.*;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-03-27
 * Time:14:01
 */
public class Text1 {
    public static void main1(String[] args) throws IOException, ClassNotFoundException {
        Animal fw=new Animal("黄","男",22);
        //File file=new File("kk.txt");
        FileOutputStream fileStream=new FileOutputStream("Mygame.ser");
        ObjectOutputStream os=new ObjectOutputStream(fileStream);
        os.writeObject(fw);
        System.out.println(fw);
        os.close();
        ObjectInputStream kk=new ObjectInputStream(new FileInputStream("kk.txt"));
        Object fw1=kk.readObject();
        Animal fw2=(Animal) fw1;
        System.out.println(fw2);
    }

    public static void main(String[] args)  {
        try{
            FileWriter witer=new FileWriter("kk.txt");
            witer.write("hello,world");
            witer.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        File my=new File("kk.txt");
        FileReader reader= null;String name=null;
        try {
            reader = new FileReader(my);
            BufferedReader kw=new BufferedReader(reader);
            name = kw.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println(name);
    }
}

class Animal implements Serializable{
    String name;
    String sex;
    int gae;
    Animal(String name,String sex,int gae)
    {
        this.name=name;
        this.sex=sex;
        this.gae=gae;
    }
    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", gae=" + gae +
                '}';
    }
}